package com.example.demo.common;

import com.example.demo.model.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

//同一判断用户的登录状态
public class SessionUtils {
    public static UserInfo getUser(HttpServletRequest request) {
        //1，获取session
        HttpSession session = request.getSession(false);//有则创建，没有则为null
        //2，判断
        if(session != null && session.getAttribute(AppVariable.SESSION_USERINFO_KEY) != null) {
            return (UserInfo) session.getAttribute(AppVariable.SESSION_USERINFO_KEY);
        }
        return null;
    }
}
